﻿CREATE FUNCTION QIC.ObjectReturnToken(@ObjectId INT)
RETURNS TABLE
AS
RETURN
(
	SELECT 
		ISNULL(parameters.parameter_id,0) PropertyId, 
		ISNULL(parameters.user_type_id,TYPE_ID('INT')) UserTypeId, 
		ISNULL(parameters.precision,10) Precision, 
		ISNULL(parameters.scale,0) Scale, 
		ISNULL(parameters.max_length,4) MaxLength,
		CAST(0 AS Bit) IsOutPut,
		CAST(0 AS Bit) IsReadOnly
	FROM sys.objects objects
	LEFT OUTER JOIN sys.parameters parameters
		ON objects.type = 'FN'
		AND parameters.object_id = objects.object_id
		AND parameters.parameter_id = 0
	WHERE objects.type in ('FN','P')
	AND objects.object_id = @ObjectId
);